﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Source.Common;

namespace Source.ServerSide
{

    public interface IEmailTemplateProvider
    {
        string LoadTemplate(string templateNameWithoutExtension);
    }

    public class EmailTemplateProvider : IEmailTemplateProvider
    {
        private readonly IConfigurationProvider configurationProvider;

        public EmailTemplateProvider(IConfigurationProvider configurationProvider)
        {
            this.configurationProvider = configurationProvider;
        }

        public string LoadTemplate(string templateNameWithoutExtension)
        {
            StreamReader sr = null;

            try
            {
                FileStream fs = new FileStream(configurationProvider.EmailTemplateDirectory + templateNameWithoutExtension + ".htm", FileMode.Open, FileAccess.Read);
                sr = new StreamReader(fs);
                return sr.ReadToEnd();
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }

    }
}
